package d1117.r214.num07;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Demo02 {
    public static void main(String[] args) {
        List<Person> list=new ArrayList<>();
        list.add(new Person("刘备","蜀国"));
        list.add(new Person("关羽","蜀国"));
        list.add(new Person("张飞","蜀国"));
        list.add(new Person("赵云","蜀国"));
        list.add(new Person("曹操","蜀国"));
        list.add(new Person("孙权","吴国"));
        //集合的遍历
        for (Person per:list){
            System.out.print(per);
        }
        System.out.println("");
        //Lambda的foreach
        list.forEach(obj->{System.out.print(obj+"---");});
        //迭代器
        //创建迭代器对象
        Iterator<Person> it=list.iterator();
        while (it.hasNext()){
           Person per= it.next();
           System.out.println(per.getName());
        }
        //传统for
        for(int i=0;i<list.size();i++){
            Person p=list.get(i);
            System.out.println(p.getCountry());
        }
        //有条件的删除，修改

       // System.out.println(list);

    }
}
class Person{
    private String name;
    private String country;

    public Person(String name, String country) {
        this.name = name;
        this.country = country;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }
    @Override
    public String toString(){
        return this.name+this.country;
    }
}